#include <algorithm>
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::for_each;
using std::vector;

//普通函数
void display(int & n)
{
    n++;
    cout << n << " ";
}

struct Printer
{
    void operator()(int n) {
        cout << n << " ";
    }
};

int main()
{
    vector<int> numbers{1, 2, 3, 4, 5};
    //普通函数
    for_each(numbers.begin(), numbers.end(), display);
    cout << endl;
    
    //函数对象
    for_each(numbers.begin(), numbers.end(), Printer());
    cout << endl;

    //lambda表达式 --> 匿名函数
    // [](){}
    // []: 捕获列表
    // (): 函数参数列表
    // {}: 函数执行体
    for_each(numbers.begin(), numbers.end(), [](int n){
        cout << n << " ";
    });
    cout << endl;

    return 0;
}

